class Solution {
private:
    struct cmp{
        bool operator() (pair<int, int>& a, pair<int, int>& b){
            return ceil(double(a.second) / double(a.first)) < ceil(double(b.second) / double(b.first));
        }
    };
public:
    int storeWater(vector<int>& bucket, vector<int>& vat) {
        int max_cishu = 0, base = 0, inc = 0, ans;
        priority_queue<pair<int, int>, vector<pair<int,int>>, cmp> p;
        bool zero_flag = false;
        for(int i = 0; i < bucket.size(); i++){
            if(!vat[i])continue;
            zero_flag = true;
            if(!bucket[i]){
                base++;
                bucket[i]++;
            }
            p.push(pair<int, int>(bucket[i], vat[i]));
        }
        if(!zero_flag)return 0;


        ans = ceil(double(p.top().second) / double(p.top().first)); 
        while(p.top().first < p.top().second){
            inc++;
            pair<int, int> temp = p.top();
            p.pop();
            temp.first++;
            p.push(temp);
            int val = inc + ceil(double(p.top().second) / double(p.top().first)); 
            ans = min(ans, val);
        }
        return base + ans;
    }
};

//2021.4.10
